<?php
namespace app\appoint\model;
use app\BaseModel;
use think\facade\Db;



class QuestionPv extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_question_pv';


    /**
     * @author chenniang
     * @DataTime: 2021-01-28 10:31
     * @功能说明:
     */
    public function dataAdd($uniacid,$q_id){

        $date = date('Y-m-d',time());

        $date_num = strtotime($date);

        $dis = [

            'uniacid' => $uniacid,

            'q_id'    => $q_id,

            'date'    => $date,

            'date_num'=> $date_num
        ];

        $info = $this->where($dis)->find();

        if(empty($info)){
            //查找上一天的数据
            $dis_last = [

                'uniacid' => $uniacid,

                'q_id'    => $q_id,

            ];

            $last = $this->where($dis_last)->value('date_num');

            if(!empty($last)){

                $num = ($date_num-$last)/86400;

                for ($i=1;$i<$num;$i++){

                    $dis_last['pv']       = 0;

                    $dis_last['date_num'] = $last+86400*$i;

                    $dis_last['date']     = date('Y-m-d',$dis_last['date_num']);

                    $this->insert($dis_last);
                }

            }

            $this->insert($dis);

        }else{

            $this->where($dis)->update(['pv'=>$info['pv']+1]);

        }

        return true;
    }




}